package teaching.exception;

import teaching.util.Response;
import teaching.util.ResponseResult;
import teaching.util.StatusCode;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Author:20201002983_郑雨蓓
 * Date: 2024/3/12
 * Description:捕获全局异常
 */
@RestControllerAdvice
public class GlobalExceptionHandle {
    //处理异常的方法1.  并确定接收的是哪种类型的异常
    @ExceptionHandler(value = NotAllowException.class)
    @ResponseBody
    public ResponseResult<Object> exceptionHandler(NotAllowException e) {
        return Response.createFailResp(e.getCode(), e.getMessage());
    }


//    //捕获AuthorizationException的异常
//    @ExceptionHandler(value = AuthorizationException.class)
//    @ResponseBody
//    public ResponseResult<Object> handleException(AuthorizationException e) {
//        return Response.createFailResp("捕获AuthorizationException的异常,权限不足！");
//    }
//
//    @ExceptionHandler(value = BindException.class)
//    @ResponseBody
//    public ResponseResult<Object> exceptionHandler(BindException e) {
//        return Response.createFailResp("提交的参数信息有误");
//    }
}
